Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
How to convert [id] to [slug] url in nextjs

I am working on nextjs and i have "blog" list and after click on blog,page redirect to "blog detail page" And current url is like

"http://localhost:3001/29"

Which is working fine,But i want my url should be like

http://localhost:3001/slug/posttitle

My current code for "Link" is which is working fine

<Link href={{pathname: "/[id]",query: { id: post.id },}}>

But for change "id" to "slug" in url,i tried with following code

<Link href={{pathname: "/[slug]",query: { title: post.title },}}>

But my url convert to "http://localhost:3001/[slug]?id=myslug"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since your root page "/" is already your blog section which contains the list of all your blog posts previews, you could create a folder called article inside the pages folder for example, and then inside that folder create your dynamic post page based on the post's slug: [slug].js. So the route would be: example.com/article/your-post-slug.

Inside your [slug].js page, you need to use getStaticPaths and getStaticProps to pre-render all the paths for each individual post and also, the content for each one.

Of course, in your main page you also have to use getStaticProps to fetch all your posts.

In your main page, wrap each post preview with a Link that points to: /article/${slug}. Hope that helps.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda